﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Omu.ValueInjecter;
using System.Threading;
using System.Diagnostics;
using System.Reflection;

namespace SerializerBenchmark
{
    class Program
    {
        static void Main(string[] args)
        {

            int counter = 0;
            POCOEntity poco=new POCOEntity { Id = 1, Name = "poco" };// = new POCOEntity();
            //Dictionary<String, String> dic = new Dictionary<string, string>();
            #region dummy data
            PropertyInfo[] props = typeof(POCOEntity).GetProperties();
            string[] propNames = props.Select(p => p.Name).ToArray();
            foreach (var pi in props)
            {
                if (pi.PropertyType == typeof(string))
                {
                    #region fill poco
                    pi.SetValue(poco, "<span style=\"color:#974806\"><p><strong><span style=\"color:#ffc000;font-size:16px\"></span></strong></p><p><span style=\"color:#974806;font-size:14px\"></span></p></span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_6\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_7\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_8\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_9\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_10\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_11\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_12\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_13\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_14\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_15\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_16\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_17\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_18\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_19\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_20\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_21\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_22\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_23\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_24\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_25\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_26\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_27\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_28\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_29\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_30\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_31\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_32\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_33\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_34\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_35\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_36\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_37\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_38\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_39\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_40\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_41\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_42\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_43\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_44\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_45\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_46\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_47\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_48\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_49\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_50\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_51\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_52\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_53\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_54\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_55\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_56\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_57\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_58\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_59\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_60\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_61\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_62\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_63\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_64\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_65\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_66\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_67\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_68\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_69\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_70\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_71\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_72\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_73\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_74\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_75\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_76\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_77\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_78\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_79\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_80\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_81\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_82\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_83\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_84\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_85\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_86\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_87\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_88\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_89\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_90\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_91\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_92\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_93\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_94\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_95\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_96\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_97\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_98\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_99\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_100\">?</span><span style=\"line-height:0px;display:none\" id=\"_baidu_bookmark_start_101\">?</span>&lt;span style=&quot;line-height:0px;display:none&quot; id=&");
                    #endregion
                }
            }
                #region fill dictionary 
//            dic["Id"] = "1";
//            dic["Name"] = @"上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12";
//            for (int i = 1; i <= 100; i++)
//            {
//                dic["Name" + i] = @"上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12
//上海--三亚--上海 2014-12-12 10:09:12";
//            }
                #endregion
            #endregion
            Stopwatch sw = new Stopwatch();
            sw.Start();
            Console.WriteLine("start");
            Parallel.For(0, 9000000, i =>
            {
                Dictionary<String, String> dic = new Dictionary<string, string>();
                //dic = new Dictionary<string, string>();
                //{
                //{ "Id", "1" }, 
                //{ "Name", "poco" } 
                //};
                //poco = EntityDictMapper.MapToEntities<POCOEntity>(dic);
                dic = EntityDictMapper.MapToDictionary<POCOEntity>(poco, propNames);
                //Dictionary<string, string> dic_mapped = EntityDictMapper.MapToDictionary(poco,"Id","Name");
                //dic.InjectFrom<EntityToDictionaryInjection>(poco);
                //poco.InjectFrom<DictionaryToEntityInjection>(dic);
                Interlocked.Add(ref counter, 1);
            });
            sw.Stop();
            Console.WriteLine(counter);
            Console.WriteLine(sw.ElapsedMilliseconds);
            Console.WriteLine("done");
            //Console.WriteLine(poco.Name);
        }
    }
}
